package com.changanw.tienchin;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.Collections;

/**
 * @author changanw
 * @description
 * @date 2023/11/15 17:32
 */
@SpringBootTest
public class GenerateCode {
  @Test
  void generateContractCode(){
    String url = "jdbc:mysql://localhost:12345/tienchin?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8";
    String path = "E:\\git\\tien-chin\\tienchin\\tienchin-contract\\src\\main";
    FastAutoGenerator.create(url, "root", "123456")
            .globalConfig(builder -> {
              builder.author("changanw") // 作者
                      .fileOverride() //覆盖已生成文件
                      .outputDir(path+"\\java"); //指定输出目录
            })
            .packageConfig(builder -> {
              builder.parent("com.changanw.tienchin") //设置父包名
                      .moduleName("contract") // 设置父包模块名
                      .pathInfo(Collections.singletonMap(OutputFile.xml,path +"\\resources\\mapper")); //设置mapperXml生成路径
            })
            .strategyConfig(builder -> {
              builder.addInclude("tienchin_contract") // 设置需要生成的表名
                      .addTablePrefix("tienchin_"); // 设置过滤表前缀
            })
            .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
            .execute();
  }
  @Test
  void generateBusinessCode(){
    String url = "jdbc:mysql://localhost:12345/tienchin?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8";
    String path = "E:\\git\\tien-chin\\tienchin\\tienchin-business\\src\\main";
    FastAutoGenerator.create(url, "root", "123456")
            .globalConfig(builder -> {
              builder.author("changanw") // 作者
                      .fileOverride() //覆盖已生成文件
                      .outputDir(path+"\\java"); //指定输出目录
            })
            .packageConfig(builder -> {
              builder.parent("com.changanw.tienchin") //设置父包名
                      .moduleName("business") // 设置父包模块名
                      .pathInfo(Collections.singletonMap(OutputFile.xml,path +"\\resources\\mapper")); //设置mapperXml生成路径
            })
            .strategyConfig(builder -> {
              builder.addInclude("tienchin_business") // 设置需要生成的表名
                      .addTablePrefix("tienchin_"); // 设置过滤表前缀
            })
            .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
            .execute();
  }
  @Test
  void generateClueCode(){
    String url = "jdbc:mysql://localhost:12345/tienchin?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8";
    String path = "E:\\git\\tien-chin\\tienchin\\tienchin-clue\\src\\main";
    FastAutoGenerator.create(url, "root", "123456")
            .globalConfig(builder -> {
              builder.author("changanw") // 作者
                      .fileOverride() //覆盖已生成文件
                      .outputDir(path+"\\java"); //指定输出目录
            })
            .packageConfig(builder -> {
              builder.parent("com.changanw.tienchin") //设置父包名
                      .moduleName("clue") // 设置父包模块名
                      .pathInfo(Collections.singletonMap(OutputFile.xml,path +"\\resources\\mapper")); //设置mapperXml生成路径
            })
            .strategyConfig(builder -> {
              builder.addInclude("tienchin_clue","tienchin_follow_record","tienchin_assignment") // 设置需要生成的表名
                      .addTablePrefix("tienchin_"); // 设置过滤表前缀
            })
            .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
            .execute();
  }
  @Test
  void generateCourseCode(){
    String url = "jdbc:mysql://localhost:12345/tienchin?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8";
    String path = "E:\\git\\tien-chin\\tienchin\\tienchin-course\\src\\main";
    FastAutoGenerator.create(url, "root", "123456")
            .globalConfig(builder -> {
              builder.author("changanw") // 作者
                      .fileOverride() //覆盖已生成文件
                      .outputDir(path+"\\java"); //指定输出目录
            })
            .packageConfig(builder -> {
              builder.parent("com.changanw.tienchin") //设置父包名
                      .moduleName("course") // 设置父包模块名
                      .pathInfo(Collections.singletonMap(OutputFile.xml,path +"\\resources\\mapper")); //设置mapperXml生成路径
            })
            .strategyConfig(builder -> {
              builder.addInclude("tienchin_course") // 设置需要生成的表名
                      .addTablePrefix("tienchin_"); // 设置过滤表前缀
            })
            .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
            .execute();
  }
  @Test
  void generateActivityCode(){
    String url = "jdbc:mysql://localhost:12345/tienchin?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8";
    String path = "E:\\git\\tien-chin\\tienchin\\tienchin-activity\\src\\main";
    FastAutoGenerator.create(url, "root", "123456")
            .globalConfig(builder -> {
              builder.author("changanw") // 作者
                      .fileOverride() //覆盖已生成文件
                      .outputDir(path+"\\java"); //指定输出目录
            })
            .packageConfig(builder -> {
              builder.parent("com.changanw.tienchin") //设置父包名
                      .moduleName("activity") // 设置父包模块名
                      .pathInfo(Collections.singletonMap(OutputFile.xml,path +"\\resources\\mapper")); //设置mapperXml生成路径
            })
            .strategyConfig(builder -> {
              builder.addInclude("tienchin_activity") // 设置需要生成的表名
                      .addTablePrefix("tienchin_"); // 设置过滤表前缀
            })
            .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
            .execute();
  }
  @Test
  void generateChannelCode(){
    String url = "jdbc:mysql://localhost:12345/tienchin?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8";
    String path = "E:\\git\\tien-chin\\tienchin\\tienchin-channel\\src\\main";
    FastAutoGenerator.create(url, "root", "123456")
            .globalConfig(builder -> {
              builder.author("changanw") // 作者
                      .fileOverride() //覆盖已生成文件
                      .outputDir(path+"\\java"); //指定输出目录
            })
            .packageConfig(builder -> {
              builder.parent("com.changanw.tienchin") //设置父包名
                      .moduleName("channel") // 设置父包模块名
                      .pathInfo(Collections.singletonMap(OutputFile.xml,path +"\\resources\\mapper")); //设置mapperXml生成路径
            })
            .strategyConfig(builder -> {
              builder.addInclude("tienchin_channel") // 设置需要生成的表名
                      .addTablePrefix("tienchin_"); // 设置过滤表前缀
            })
            .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
            .execute();
  }
}